package com.song.shop.io;

import java.io.*;

/**
 * @author Song Yinghui
 * @date 2019/2/12
 * @Version 1.0
 */
public class IO {
    public static void main(String[] args) {
        methodStream();
        System.out.println("main线程----");
    }

    private static void methodReader() {
        try {
            Reader reader = new FileReader("./resources/111.pdf");
            Writer writer = new FileWriter("./resources/222.pdf");
            System.out.println(Thread.currentThread().getName());
            System.out.println("读取开始-------");
            int data = reader.read();
            while (data != -1){
                writer.write(data);
                data = reader.read();
            }
            System.out.println("读取结束-----");
            reader.close();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void methodStream() {
        try {
            InputStream inputStream = new FileInputStream("./resources/111.pdf");
            OutputStream outputStream = new FileOutputStream("./resources/222.pdf");
            System.out.println("读取开始-------");
            int data = inputStream.read();
            while (data != -1){
                outputStream.write(data);
                data = inputStream.read();
            }
            System.out.println("读取结束-----");
            inputStream.close();
            outputStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
